package com.lanwf.admin.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.lanwf.admin.utils.Cons;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: Lanwf
 * @Date: 2021/12/23 17:57
 * @Description:
 */
public class AdminLockscreenInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation inv) {
        Controller c = inv.getController();
        HttpServletRequest request = c.getRequest();
        String requestURI = request.getRequestURI();
        String lockCookie = c.getCookie(Cons.LOCKSCREEN);

        String unionPath = Cons.prj + "/admin/lockscreen";
        if(StrKit.notBlank(lockCookie) && !unionPath.equals(requestURI)){
            c.redirect("/admin/lockscreen");
            return;
        }

        inv.invoke();
    }

}
